package com.road7.mina.protobufmsg;

import java.io.IOException;
import java.net.InetSocketAddress;

import org.apache.mina.core.service.IoAcceptor;
import org.apache.mina.core.session.IoSessionConfig;
import org.apache.mina.filter.codec.ProtocolCodecFilter;
import org.apache.mina.filter.logging.LoggingFilter;
import org.apache.mina.transport.socket.nio.NioSocketAcceptor;

import com.road7.mina.customcodecfactory.ProtobufStrictCodecFactory;

/**
 * @Description :
 * @FileName: Server.java
 * @Author :WeiHui.Zhang
 * @Data : 2015年11月23日 下午8:19:49
 * @Version:V1.00
 */
public class Server {

	public static final int PORT = 10000;

	public static void main(String[] args) throws IOException {

		IoAcceptor acceptor = new NioSocketAcceptor(Runtime.getRuntime().availableProcessors() + 1);

		IoSessionConfig config = acceptor.getSessionConfig();

		config.setMaxReadBufferSize(1024 * 4);

		acceptor.getFilterChain().addLast("logger", new LoggingFilter());

		acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new ProtobufStrictCodecFactory()));

		acceptor.setHandler(new ServerHandler());

		acceptor.setDefaultLocalAddress(new InetSocketAddress(PORT));

		acceptor.bind();
	}
}
